package com.loocup.demo1.config;

import com.loocup.demo1.aop.BeforeMethod;
import com.loocup.demo1.bean.CustomerService;
import org.springframework.aop.framework.ProxyFactoryBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class AdviceConfig {

    @Bean
    public CustomerService customerService(){
        CustomerService customerService = new CustomerService();
        customerService.setName("jack");
        customerService.setUrl("www.loocup.com");
        return customerService;
    }

    @Bean
    public BeforeMethod beforeMethod(){
        return new BeforeMethod();
    }

    @Bean(name = "customerServiceProxy")
    public ProxyFactoryBean proxyFactoryBean(){
        ProxyFactoryBean proxyFactoryBean = new ProxyFactoryBean();
        proxyFactoryBean.setTargetName("customerService");
        proxyFactoryBean.setInterceptorNames("beforeMethod");
        return proxyFactoryBean;
    }
}
